/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Modelo;

import BBDD.BaseConection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author David
 */
public class Cliente {
     public String getNombre() {
        return Nombre;
    }

    public void setNombre(String Nombre) {
        this.Nombre = Nombre;
    }

    public String getApellido() {
        return Apellido;
    }

    public void setApellido(String Apellido) {
        this.Apellido = Apellido;
    }

    public String getUsuario() {
        return usuario;
    }

    public void setUsuario(String usuario) {
        this.usuario = usuario;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getNumCliente() {
        return numCliente;
    }

    public void setNumCliente(int numCliente) {
        this.numCliente = numCliente;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
    public Cliente obtenerCliente (String nombreCliente){
     Cliente cliente = new Cliente();
     Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            conn = DriverManager.getConnection(
                    BaseConection.getCadenaLocal(),
                    BaseConection.getUser(),
                     BaseConection.getPassword());
            stmt = conn.createStatement();
            rs = stmt.executeQuery("SELECT NOMBRE, APELLIDO,NUM_CLIENTE, EMAIL FROM USERS_CLIENTE WHERE USUARIO='"
                    + nombreCliente+"'");
            if (rs.next()) {
                 cliente.setNombre(rs.getString("NOMBRE"));
                 cliente.setApellido(rs.getString("APELLIDO"));
                 cliente.setNumCliente(Integer.parseInt(rs.getString("NUM_CLIENTE")));
                 cliente.setEmail(rs.getString("EMAIL"));
            }
             } catch (SQLException exceptionSql) {
            System.out.print("Error:" + exceptionSql.getMessage());
        }
     return cliente;
    }
    public String ObtenerNombre (String numCliente){
     Cliente cliente = new Cliente();
     Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            conn = DriverManager.getConnection(
                    BaseConection.getCadenaLocal(),
                    BaseConection.getUser(),
                    BaseConection.getPassword());
            stmt = conn.createStatement();
            rs = stmt.executeQuery("SELECT NOMBRE, APELLIDO, EMAIL FROM USERS_CLIENTE WHERE num_cliente="
                    + numCliente);
            if (rs.next()) {
                 cliente.setNombre(rs.getString("NOMBRE"));
                 cliente.setApellido(rs.getString("APELLIDO"));
                 cliente.setEmail(rs.getString("EMAIL"));
            }
             } catch (SQLException exceptionSql) {
            System.out.print("Error:" + exceptionSql.getMessage());
        }
     return cliente.getNombre();
    }
    
    public Boolean ingresarCliente(Cliente cli){
        Connection conn = null;
        Cliente cliente = new Cliente();
        int num =1;
        try {
            conn = DriverManager.getConnection(
                    BaseConection.getCadenaLocal(),
                    BaseConection.getUser(),
                    BaseConection.getPassword());
            
            PreparedStatement pst =(PreparedStatement) conn.prepareStatement
             ("INSERT INTO USERS_CLIENTE(NOMBRE, APELLIDO, USUARIO, PASSWORD, " 
                +"NUM_CIENTE, EMAIL)values (?,?,?,?,?,?)");
          
          pst.setString(1, cliente.getNombre());  
          pst.setString(2, cliente.getApellido());        
          pst.setString(3, cliente.getEmail());
          pst.setString(4, cliente.getUsuario());
          pst.setInt(5,num);
          pst.setString(6, cliente.getPassword());
                
            
             } catch (SQLException exceptionSql) {
            System.out.print("Error:" + exceptionSql.getMessage());
        }
        
        return true;
    }
  
    
    //parametros
    private String Nombre;
    private String Apellido;
    private String usuario;
    private String password;
    private int numCliente;
    private String email;
}
